package com.web.sys.sercice;

import java.util.List;

import javax.inject.Inject;

import org.springframework.stereotype.Service;

import com.web.sys.dao.ISysSourceDao;
import com.web.sys.model.SysSource;

@Service("sysSourceService")
public class SysSourceService implements ISysSourceService {
	
	@Inject
	private ISysSourceDao sysSourceDao;

	@Override
	public List<SysSource> queryAllNavigation() {
		List<SysSource> nav=sysSourceDao.list("from SysSource where pcode is null");
		return nav;
	}

	@Override
	public List<SysSource> queryAllSource(String text) {
		SysSource src=sysSourceDao.querySourceByName(text);
		List<SysSource> nav=sysSourceDao.list("from SysSource where pcode =?",src.getCode());
		return nav;
	}

	@Override
	public List<SysSource> queryAllNavigationByRole(String role) {
		List<Object> srcList=sysSourceDao.listBySql("select srccode from sys_role_src where rolecode=?", role, String.class, true);
		StringBuffer sb=new StringBuffer("from SysSource where pcode is null and code in(");
		for(int i=0,size=srcList.size();i<size;i++){
			if(i==0)sb.append("?");
			else sb.append(",?");
			
		}
		sb.append(")");
		String hql=sb.toString();
		List<SysSource> nav=sysSourceDao.list(hql,srcList.toArray());
		return nav;
	}

}
